﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FlexiCache;
using System.Collections.Specialized;
using UnitTests.IISSimulator;

namespace CLOComponentlibCSFixture.FlexiCache
{
    [TestClass]
    public class CacheCleanupUtilityFixture
    {
        [TestInitialize]
        public void Setup()
        {
        }

        [TestCleanup]
        public void TearDown()
        {
        }

        [TestMethod]
        public void Test001_CreateAndExecuteWorkflow()
        {
            HttpSimulator sim = null;
            CacheCleanupUtility cacheCleaner = null;

            try
            {
                sim = new HttpSimulator("/", true);
                sim.SimulateRequest();
                System.Web.HttpContext.Current.Application.Clear();

                CacheCleanupUtility.CreateInstance();
                cacheCleaner = (CacheCleanupUtility)System.Web.HttpContext.Current.Application["CacheCleanupUtilityHolder"];
                IEnumerator<IExpirationProvider> workflow = cacheCleaner.CreateWorkflow();
                cacheCleaner.ExecuteWorkflow(workflow);
            }
            finally
            {
                if (cacheCleaner != null)
                    cacheCleaner.Dispose();
                if (sim != null)
                    sim.Dispose();
            }
        }
    }
}
